<extend name="Public:main" />
<block name="title">订单</block>
<block name="body">
<body ng-app="myApp" ng-controller="Ctrl" ng-cloak>
    <div class="nav_top flex">
        <a  href="/index.php/Home/Transaction/purchase">
            <i></i>
        </a>
        <div class="flex1">
            订单
        </div>
        <a  href="javascript:void(0)">

        </a>
    </div>
    <div style="height: 0.44rem;"></div>
    <div class="xpay_m">
        <ul>
            <a href="/index.php/Home/Transaction/unOrderList">
                <li <if condition="$src eq 1">class="active8"</if>>
                    未完成
                </li>
            </a>
            <a href="/index.php/Home/Transaction/confirmOrderList">
                <li <if condition="$src eq 2">class="active8"</if>>
                    进行中
                </li>
            </a>
            <a href="/index.php/Home/Transaction/completeOrderList">
                <li <if condition="$src eq 3">class="active8"</if>>
                    已完成
                </li>
            </a>
        </ul>
    </div>
    <div style="height: 0.1rem;"></div>
    <div class="pay_list">
        <ul>
            <li class="flex" ng-repeat="log in logs">
                <div ng-if="log.profilephoto == '' || log.profilephoto == null">
                    <img src="__PUBLIC__/vpay/images/shezhi_icon_head.png">
                </div>
                <div ng-if="log.profilephoto != ''">
                    <img ng-src="{{ log.profilephoto }}">
                </div>
                <div class="flex1">
                    <label>
                        {{ log.buyer }}
                    </label>
                    <p>
                        时间：{{ log.createtime }}
                    </p>
                </div>
                <div style="width: 0.7rem;overflow: hidden">
                    <label>{{ log.entrustnum }}</label>
                    <button ng-if="log.status == 2">
                        确认打款
                    </button>
                </div>
            </li>
        </ul>
    </div>
    </div>
</body>
<block name="custom_js">
    <script>
        var app = getApp('myApp', []);
        app.controller('Ctrl', function ($scope, $http) {
            // 当前页数
            $scope.p = 0;
            // 加载完毕标志
            $scope.endflg = 0;
            // 防止重复加载
            $scope.busy = false;
            // 存放数据
            $scope.logs = [];
            // 请求数据方法
            $scope.loadMore = function(){

                if($scope.endflg == 0){
                    if($scope.busy){
                        return false;
                    }
                    $scope.busy = true;
                    $http({
                        method:'POST',
                        data:{
                            "p" : $scope.p
                        },
                        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                        transformRequest: function(obj) {
                            var str = [];
                            for (var p in obj) {
                                str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                            }
                            return str.join("&");
                        },
                        url: "/index.php/Home/Transaction/completeOrderList?p="+$scope.p,
                    }).then(function successCallback(response) {
                        $scope.busy = false;
                        if(response.data.data != '' && response.data.data != null){
                            if($scope.p > 0) {
                                layer.msg("正在加载...", {time: 500});
                            }
                        } else {
                            layer.msg("已经全部加载完了...", {time:500});
                            $scope.endflg = 1;
                            return false;
                        }
                        $scope.p++;
                        if(response.data.code == -1){
                            layer.msg(response.data.msg,{time:1500})
                        }else{
                            if(response.data.data == null){
                                layer.msg(response.data.msg,{time:1500});
                            } else {
                                // 组织数据
                                for (var i in response.data.data) {
                                    $scope.logs.push(response.data.data[i]);
                                }
                            }
                        }
                    }, function errorCallback(response) {
                        errorHandle(response);
                    });
                }else{
                    layer.msg("已经全部加载完了...", {time:500});
                }
            };
            // 进页面先加载一次数据
            $scope.loadMore();

            $(window).scroll(function(){
                var scrollTop = $(this).scrollTop();
                var scrollHeight = $(document).height();
                var windowHeight = $(this).height();
                if(scrollTop + windowHeight == scrollHeight){
                    $scope.loadMore();
                }
            });
        });
    </script>
</block>
</block>